(function(Play){
	
	var audio = new Audio();
	Play.audio = audio;
	var control = $("control");
	var progressbar = $("progressbar");
	var p_played = $("p_played");
	var p_load = $("p_load");
	
	var nextplay = $("nextplay");
	var play = $("play");
	var preplay = $("preplay");
	
	
	var sname = $("sname");
	var ssinger = $("ssinger");
	var salbum = $("salbum");
	
	//歌词
	var songlrc = $("songlrc");
	
	//按钮事件绑定
	_bindEvent(play,"click",function(event){
		_changMucis(Play.current());
	})
	_bindEvent(preplay,"click",function(event){
		_changMucis(Play.prev());
	})
	_bindEvent(nextplay,"click",function(event){
		_changMucis(Play.next());
	})
	
	
	//播放事件绑定
	_bindEvent(audio,"progress",function(event){
		p_load.style.width=audio.buffered.end(.1)/audio.duration*100+"%";
	})
	_bindEvent(audio,"timeupdate",function(event){
		//添加播放进度条显示
		p_played.style.width=audio.currentTime/audio.duration*100+"%";
	})
	
	
	function _changMucis(muc){
		audio.src =  muc.songUrl;
		_changSongShowInfo(muc);
		audio.play();
		_loadlrc();
	}
	
	
	//改变当前播放歌曲显示信息
	function _changSongShowInfo(muc){
		sname.innerHTML=muc.songName;
		ssinger.innerHTML=muc.singerName;
		salbum.innerHTML=muc.album;
		
	}
	
	function _loadlrc(){
		var xmlhttp = new XMLHttpRequest();
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				_analysisLrc(xmlhttp.responseText);
			}
		}
		xmlhttp.open("GET","http://192.168.5.30/optimize/ttpod/lrc/1.lrc",true);
		xmlhttp.send();
		
	}
	function _analysisLrc(lrc){
		var lrcs = lrc.split("\n");
		var lrcinfo = {};
		for(var i=0,n=lrcs.length;i<n;i++){
			var obj = {time:null,timesec:null,value:null};
			var lrc = lrcs[i];
			var info = lrc.split("]");
			obj.time = info[0].replace("[","");
			var timeTemp = obj.time.split(":");
			//如果是标签：返回
			if(isNaN(timeTemp[0]-0)){
				continue;
			}
			obj.timesec = timeTemp[0]*60+timeTemp[1]-0;
			console.log(obj.timesec);
			obj.value = info[1];
			lrcs[i]=obj;
		}
		
		_addLrcToDom(lrcs);
	}
	function _addLrcToDom(lrcs){
		var ul = document.createElement("ul");
		ul.className="lrc";
		for(var i=0,n=lrcs.length;i<n;i++){
			var lrc = lrcs[i];
			var li = document.createElement("li");
			li.innerHTML=lrc.value;
			ul.appendChild(li);
		}
		songlrc.appendChild(ul);
	}
	//绑定事件
	function _bindEvent(ele,type,func){
		ele.addEventListener(type,func);
	}
})(Play);